<style>
    .offline-input .card{
        margin-top: 15px;
        margin-bottom: 0;
    }
    .offline-input .card .form-group:last-child{
        margin-bottom: 0;
    }
    .offline-input .card .delete-icon{
       margin: 5px;
        cursor: pointer;
    }
</style>
<div id="coupon" class="tab-pane coupon-tab-pane">
    <div class="row">
        <div class="col-md-12">
            <form id="wizardForm" class="form-horizontal" method="post" action="" enctype="multipart/form-data">
                {{ csrf_field() }}
                <input type="hidden" value="coupon" name="data[prize][type_code]">
                <input type="hidden" value="1" name="data[prize][resource]">
                <div class="row">
                    <div class="col-xs-4 app">
                        <div class="phone-view">
                            <div class="app-view">
                                <div class="app-mainC">
                                    <div class="app-alert">
                                        <div class="app-alert-input">
                                            <div class="app-alert-image">
                                                <img src="/images/admin/promotion_default.png">
                                            </div>
                                            <div class="app-alert-title">
                                                <div class="title-name">活动名称</div>
                                                <div class="title-endtime">有效期:
                                                </div>
                                                <div class="title-endtime"><span class="title-endtime-span"></span>
                                                </div>
                                            </div>

                                        </div>
                                        <div class="app-alert-word">
                                            <div class="app-alert-code"></div>
                                            <div class="app-alert-text">
                                                长按复制卷码去兑奖
                                            </div>
                                        </div>

                                    </div>
                                    <div class="app-btn"></div>
                                    <div class="app-paper"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-8">
                        <div class="row">
                            <div class="col-sm-12">
                                <div class="form-group">
                                    <label class="col-sm-2 col-sm-offset-1 control-label">奖品名称</label>
                                    <div class="col-sm-7 col-sm-offset-1">
                                        <input class="form-control prize-code-name" type="text" name="data[prize][name]"
                                               datatype="s1-20" ajaxurl="/web/prize/checkName/0">
                                        <div class="info"><span
                                                    class="Validform_checktip"></span><span
                                                    class="dec"><s class="dec1">&#9670;</s><s
                                                        class="dec2">&#9670;</s></span></div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 col-sm-offset-1 control-label">有效时间</label>
                                    <div class="col-sm-7 col-sm-offset-1">
                                        <div class="row service-charges">
                                            <div class="col-md-5 service-charges-name service-charges-name-0"
                                                 style="padding-left: 15px;">
                                                <input type="text" placeholder="开始时间" required=""
                                                       name="data[prize][expired_start]" data-msg="请输入开始时间"
                                                       class="form-control datetimepicker codestartdate" datatype="*"
                                                       nullmsg="选择开始时间">
                                                <div class="info"><span
                                                            class="Validform_checktip"></span><span
                                                            class="dec"><s class="dec1">&#9670;</s><s class="dec2">&#9670;</s></span>
                                                </div>
                                            </div>
                                            <div class="col-md-5 service-charges-remark service-charges-remark-0">
                                                <input type="text" placeholder="结束时间" required=""
                                                       name="data[prize][expired_end]" data-msg="请输入结束时间"
                                                       class="form-control datetimepicker codeenddate" datatype="*"
                                                       nullmsg="选择结束时间">
                                                <div class="info"><span
                                                            class="Validform_checktip"></span><span
                                                            class="dec"><s class="dec1">&#9670;</s><s class="dec2">&#9670;</s></span>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                {{--<input class="form-control" value="0" type="hidden" name="data[prize][stock_number]"/>--}}
                 {{--<div class="form-group">--}}
                                    {{--<label class="col-sm-2 col-sm-offset-1 control-label">奖品库存</label>--}}
                                    {{--<div class="col-sm-7 col-sm-offset-1">--}}
                                        {{--<input class="form-control" type="number" placeholder="最大为9999999"--}}
                                               {{--required="required" name="data[prize][stock_number]" number="true"--}}
                                               {{--max="9999999" min="0" datatype="/^[1-9][0-9]{0,6}$/"--}}
                                               {{--nullmsg="输入库存数量" errormsg="只能输入1~9999999的数字">--}}
                                        {{--<div class="info"><span--}}
                                                    {{--class="Validform_checktip"></span><span--}}
                                                    {{--class="dec"><s class="dec1">&#9670;</s><s--}}
                                                        {{--class="dec2">&#9670;</s></span></div>--}}
                                    {{--</div>--}}
                                {{--</div>--}}
                                {{--<div class="form-group">--}}
                                    {{--<label class="col-sm-2 col-sm-offset-1 control-label">卷码类型</label>--}}
                                    {{--<div class="col-sm-7 col-sm-offset-1">--}}
                                        {{--<label class="radio-inline displayable">--}}
                                            {{--<input type="radio" name="data[prize][voucher_type]" class="nocode"--}}
                                                   {{--value="0">--}}
                                            {{--无券码--}}
                                        {{--</label>--}}
                                        {{--<label class="radio-inline">--}}
                                            {{--<input type="radio" name="data[prize][voucher_type]" class="samecode"--}}
                                                   {{--value="1" checked> 统一码--}}
                                        {{--</label>--}}
                                        {{--<label class="radio-inline">--}}
                                            {{--<input type="radio" name="data[prize][voucher_type]" class="slfcode"--}}
                                                   {{--value="2" disabled="disabled"> 自定义导入--}}
                                        {{--</label>--}}
                                        {{--<span class="help-block">注意：奖品保存后券码类型不能修改。</span>--}}
                                    {{--</div>--}}
                                {{--</div>--}}
                                {{--<div class="samecouponCode-input">--}}
                                    {{--<div class="form-group">--}}
                                        {{--<label class="col-sm-2 col-sm-offset-1 control-label">统一卷码</label>--}}
                                        {{--<div class="col-sm-7 col-sm-offset-1">--}}
                                            {{--<input class="form-control input-same-code" type="text" placeholder="请输入卷码"--}}
                                                   {{--name="data[prize][voucher_code]" ignore="ignore"/>--}}
                                            {{--<div class="info"><span--}}
                                                        {{--class="Validform_checktip"></span><span--}}
                                                        {{--class="dec"><s class="dec1">&#9670;</s><s--}}
                                                            {{--class="dec2">&#9670;</s></span></div>--}}
                                        {{--</div>--}}
                                    {{--</div>--}}
                                {{--</div>--}}
                                <div class="slfcouponCode-input displayable">
                                    <div class="form-group">
                                        <label class="col-sm-2 col-sm-offset-1 control-label">上传卷码</label>
                                        <div class="col-sm-7 col-sm-offset-1">
                                            <input class="form-control csv fileInput" type="file" name="upfile"
                                                   ignore="ignore" data-for="data[prize][voucher_link]">
                                            <input type="hidden" name="data[prize][voucher_link]" value="">
                                            <div class="info"><span
                                                        class="Validform_checktip"></span><span
                                                        class="dec"><s class="dec1">&#9670;</s><s
                                                            class="dec2">&#9670;</s></span></div>
                                            <span class="help-block">"提示：CSV格式，每次最多导入10000条记录。下载["
                                                <a href="/admin/卷码示例.csv" target="_blank">示例</a>
                                                "]"</span>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 col-sm-offset-1 control-label">兑奖方式</label>
                                    <div class="col-sm-7 col-sm-offset-1">
                                        <label class="radio-inline">
                                            <input type="radio" name="data[prize][exchange_method]" class="onlineprize" value="0" checked>线上网址兑换
                                        </label>
                                        <label class="radio-inline">
                                            <input type="radio" name="data[prize][exchange_method]" class="offlineprize" value="1">线下门店兑换
                                        </label>
                                    </div>
                                </div>

                                <div class="form-group online-input">
                                    <label class="col-sm-2 col-sm-offset-1 control-label">兑奖链接</label>
                                    <div class="col-sm-7 col-sm-offset-1">
                                        <input class="form-control exchange_url" type="text"
                                               placeholder="例如：http://www.chinamcloud.com"
                                               name="data[prize][exchange_url]">
                                        <div class="info"><span
                                                    class="Validform_checktip"></span><span
                                                    class="dec"><s class="dec1">&#9670;</s><s
                                                        class="dec2">&#9670;</s></span></div>
                                    </div>
                                </div>

                                <div class="form-group offline-input" style="display:none;">
                                    <label class="col-sm-2 col-sm-offset-1 control-label">自定义字段</label>
                                    <div class="col-md-7 col-sm-offset-1">
                                        <button type="button" class="btn btn-info add-group">&nbsp;&nbsp;+新建&nbsp;&nbsp;</button>
                                        <div class="card coupon-card">
                                            <div class="content">
                                                <div class="form-group">
                                                    <label class="col-md-1 col-sm-1 control-label">01</label>
                                                    <div class="col-md-7 col-sm-7">
                                                        <input class="form-control" type="text"
                                                               name="fields[0]"
                                                               placeholder="请输入字段名称"
                                                               data-msg="请输入字段名称"/>
                                                    </div>
                                                    <div class="delete-icon">
                                                        <img src="/images/admin/delet_red.png" class="delete-icon">
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                {{--<div class="form-group">--}}
                                    {{--<label class="col-sm-2 col-sm-offset-1 control-label">奖品标签</label>--}}
                                    {{--<div class="col-sm-7 col-sm-offset-1">--}}
                                        {{--<textarea class="form-control" type="text" name="data[prize][tag]"--}}
                                                  {{--ignore="ignore"></textarea>--}}
                                        {{--<div class="info"><span--}}
                                                    {{--class="Validform_checktip"></span><span--}}
                                                    {{--class="dec"><s class="dec1">&#9670;</s><s--}}
                                                        {{--class="dec2">&#9670;</s></span></div>--}}
                                    {{--</div>--}}
                                {{--</div>--}}
                                <div class="form-group backgroundImg-container">
                                    <label class="col-sm-2 col-sm-offset-1 control-label">奖品图片</label>
                                    <div class="col-sm-7 col-sm-offset-1">
                                        <input type="file" name="upfile" accept="image/gif,image/jpeg,image/png"
                                               data-target="uploadBackgroundFile"
                                               data-preview-file-type="text" class="form-control fileInput"
                                               value="" title="" data-for="data[prize][background_image]"
                                               maxFileSize="200K" maxImageWidth="100" maxImageHeight="100">
                                        <input type="hidden"
                                               name="data[prize][background_image]"
                                               value="">
                                        <div class="info"><span
                                                    class="Validform_checktip"></span><span
                                                    class="dec"><s class="dec1">&#9670;</s><s
                                                        class="dec2">&#9670;</s></span></div>
                                        <span class="help-block">100*100像素，支持PNG、JPG格式，小于200KB</span>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-sm-10 col-sm-offset-1">
                                        <div class="panel panel-info">
                                            <div class="panel-heading">
                                                <h3 class="panel-title">奖品赞助商信息</h3>
                                            </div>
                                            <div class="panel-body sponsor_panel">
                                                <div class="sponsor_form">
                                                    <div class="row">·

                                                        <div class="col-sm-12">
                                                            <img src="/images/admin/delet_red.png"
                                                                 class="sponsor_delet pull-right mgb10 mgr30">
                                                        </div>
                                                        <div class="form-group">
                                                            <label class="col-sm-3 control-label">赞助商信息</label>
                                                            <div class="col-sm-8 ">
                                                                <input class="form-control" type="text"
                                                                       name="data[sponsor][name][]" datatype="sponsor">
                                                                <div class="info"><span
                                                                            class="Validform_checktip"></span><span
                                                                            class="dec"><s class="dec1">&#9670;</s><s
                                                                                class="dec2">&#9670;</s></span></div>
                                                            </div>
                                                        </div>
                                                        <div class="form-group">
                                                            <label class="col-sm-3 control-label">商家Logo</label>
                                                            <div class="col-sm-8">
                                                                <input type="file" name="upfile"
                                                                       accept="image/gif,image/jpeg,image/png" data-target="uploadLogoFile"
                                                                       data-preview-file-type="text"
                                                                       class="form-control fileInput" value="" title=""
                                                                       data-for="data[sponsor][logo][]"
                                                                       maxFileSize="200K" maxImageWidth="100"
                                                                       maxImageHeight="100">
                                                                <input type="hidden" name="data[sponsor][logo][]"
                                                                       value="">
                                                                <div class="info"><span
                                                                            class="Validform_checktip"></span><span
                                                                            class="dec"><s class="dec1">&#9670;</s><s
                                                                                class="dec2">&#9670;</s></span></div>
                                                                <span class="help-block">支持PNG、JPG格式，小于200KB</span>
                                                            </div>
                                                        </div>
                                                        <div class="form-group">
                                                            <label class="col-sm-3 control-label">曝光率</label>
                                                            <div class="col-sm-7">
                                                                <input class="form-control ptr" type="number"
                                                                       name="data[sponsor][percent][]" datatype="/^100$|^[0-9]{1,2}$/"
                                                                       min="0" value="0" errormsg="只能输入0~100的整数">
                                                                <div class="info"><span
                                                                            class="Validform_checktip"></span><span
                                                                            class="dec"><s class="dec1">&#9670;</s><s
                                                                                class="dec2">&#9670;</s></span></div>
                                                            </div>
                                                            <label class="col-sm-1 control-label ptl textl">%</label>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="pull-center mgud">
                                                    <button type="button"
                                                            class="btn btn-info btn-wd btn-finish panel-sponsor-butten">
                                                        添加一个新的赞助商
                                                    </button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
                <div class="footer pull-center">
                    <button type="submit" class="btn btn-submit btn-info btn-fill btn-wd btn-finish sponsor_sur">完成
                    </button>
                    <div class="clearfix"></div>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
	function init() {
	    //==================================================
	    $('.onlineprize').click(function(){
            $('.online-input').show();
            $('.offline-input').hide();
        });
        $('.offlineprize').click(function(){
            $('.online-input').hide();
            $('.offline-input').show();
        });
        function sort(){
            $('.coupon-card.card .form-group').each(function(i,ele){
                var index = (i+1)<10?'0'+(i+1):(i+1);
                $(ele).find('.control-label').text(index);
                $(ele).find('input').attr('name','fields['+i+']');
            });
        }
        $('.add-group').click(function(e) {
            var length = $('.coupon-card.card .form-group').length+1;
            var currentIndex = (length < 10 ? '0' + length : length);
            var html = '<div class="form-group">' +
                    '       <label class="col-md-1 col-sm-1 control-label">' + currentIndex + '</label>' +
                    '       <div class="col-md-7 col-sm-7">' +
                    '         <input class="form-control" type="text"' +
                    '                 name="fields['+ $('.coupon-card.card .form-group').length +']"' +
                    '                 placeholder="请输入字段名称"' +
                    '                 data-msg="请输入字段名称"/>' +
                    '       </div>' +
                    '       <div class="delete-icon">' +
                    '           <img src="/images/admin/delet_red.png" class="delete-icon">' +
                    '       </div>' +
                    '  </div>';
            $('.coupon-card.card .content').append(html);
        });
        //删除自定义字段
        $('.coupon-card').on('click','.delete-icon',function () {
            $(this).closest('.form-group').remove();
            sort();
        });
        //===================================================

		$('.nocode').click(function () {
			$('.samecouponCode-input').addClass('displayable');
			$('.slfcouponCode-input').addClass('displayable');
			$('.app-alert-word').addClass('displayable');
		});
		$('.samecode').click(function () {
			$('.app-alert-code').empty();
			$('.samecouponCode-input').removeClass('displayable');
			$('.slfcouponCode-input').addClass('displayable');
			$('.app-alert-word').removeClass('displayable');
		});
		$('.slfcode').click(function () {
			$('.app-alert-code').html('0123456789');
			$('.samecouponCode-input').addClass('displayable');
			$('.slfcouponCode-input').removeClass('displayable');
			$('.app-alert-word').removeClass('displayable');
		});

		$('.panel-sponsor-butten').on('click', function () {
			var addObj = $(this).parent('.mgud');
			$.get('/web/prize/sponsor', function (res) {
				addObj.before(res);
				var fileInputObj = addObj.prev('.sponsor_form').find('.fileInput');
				initFileInput(fileInputObj);
			});
		});
		$('.sponsor_panel').on('click', '.sponsor_delet', function () {
			if ($('.sponsor_form').length == 1) {
				return;
			}
			$(this).parents('.sponsor_form').remove();
		});

		$('.prize-code-name').blur(function () {
			if ($('.prize-code-name').val() == '') {
				$('.title-name').empty();
				$('.title-name').html('活动名称');
			}
		});
		$('.prize-code-name').on('input', function () {
			$('.title-name').empty();
			var name = $('.prize-code-name').val();
			$('.title-name').html(name);
		});

        /*统一卷码输入事件*/
		$('.input-same-code').on('input', function () {
			$('.app-alert-code').empty();
			var name = $('.input-same-code').val();
			$('.app-alert-code').html(name);
		});

		$('.datetimepicker').on('blur', function (e) {
//		    console.log(e);
			var enddate = $(this).val();
			$('.title-endtime-span').html(enddate);
		})

		$('.fileInput').each(function () {
			initFileInput($(this));
		});
//        hh:mm:ss
		$(".datetimepicker").datetimepicker({format: 'YYYY-MM-DD hh:mm:ss'});

        $('.submit').on('click',function(){
            console.log('hdfsdghfgsd');
        });
		initValidform($('#wizardForm'));
	}
</script>

